package com.baizhi.hospital.controller;

import com.baizhi.hospital.entity.User;
import com.baizhi.hospital.service.UserService;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpSession;


@Controller
public class UserController {
    @Autowired
    private UserService userService;
    @RequestMapping("/login")
    public String login(String userName, String password, HttpSession httpSession,String code){
        /*if(code.equals(httpSession.getAttribute(code))){
            User user = userService.selectByUserNameAndPassword(userName, password);
            if(user!=null){
                return "redirect:/main.jsp";
            }else{
                return "login";
                *//* return "redirect:/looo/new.jsp";*//*
            }
        }else{
            return "login";
        }*/
        if(code.equals(httpSession.getAttribute("validationCode"))){
            System.out.println(code);
            User user = userService.selectByUserNameAndPassword(userName, password);
            if(user!=null) {
                return "redirect:/main.jsp";
            }
        }
        return "login";
    }
}
